<?php

class App_Helper_Mcmp {
   
   private $flashvars = array(      
      'checkVersion' => '',
      'promptVersion' => '',
      'playlist' => '',
      'plresize' => '',
      'plfolders' => '',
      'mediadir' => '',
      'dfile' => '',
      'dfileaction' => '',
      'defpreclip' => '',
      'desctxtcolor' => '',
      'descbgcolor' => '',
      'infotype' => '',
      'infohead' => '',
      'infotxt' => '',
      'infoheadcl' => '',
      'infotxtcl' => '',
      'infobg' => '',
      'infobutton' => '',
      'definfo' => '',
      'bgcolor' => '',
      'fullscreenmode' => '',
      'buf' => '',
      'zoom' => '',
      'dlinks' => '',
      'downloadDir' => '',
      'showfileURLs' => '',
      'directlinkURL' => '',
      'optmenu' => '',
      'aseq' => '',
      'aseqd' => '',
      'imgdur' => '',
      'swfdur' => '',
      'startvol' => '',
      'allowsearch' => '',
      'searchorder' => '',
      'searchdesc' => ''
   );
   
   private $params = array(
      //'mcplayerfile' => 'mcmp720x360_player.swf',
      'movie' => '/flash/mcmp720x360_player.swf',
      'width' => '720',
      'height' => '360',
      'quality' => 'best',
      'allowScriptAccess' => 'always',
      'allowFullScreen' => 'true'
   );
   
   private $attributes = array(
      'id' => 'player',
      'name' =>  'player'
   );
   
   public $id = 'flashcontent';
   public $flashVersion='7.0.0';
   
   public function setFlashVars($flashvars=array()) {
      foreach($flashvars as $k => $v) {
         $this->flashvars[$k] = $v;
      }
   }
   
   public function setParams($params=array()) {
      foreach($params as $k => $v) {
         $this->params[$k] = $v;
      }
   }
   
   public function setAttributes($attributes=array()) {
      foreach($attributes as $k => $v) {
         $this->attributes[$k] = $v;
      }
   }
   
   
   
   private function _getVarsJS($name) {
      $str = "var $name = {\n";
      foreach($this->$name as $k => $v) {
         if(strlen(trim($v))) {
            $str .= sprintf("\t'%s' : '%s',\n", $k, $v);
         }
      }
      $str = rtrim($str, ",\n");
      $str .= "\n};\n";
      return $str;
   }
   
   public function __construct($flashvars=array(), $params=array(), $attributes=array()) {
      
      foreach($flashvars as $k => $v) {
         if(strlen(trim($v))) {
            $this->flashvars[$k] = $v;
         }
      }
      
      foreach($params as $k => $v) {
         if(strlen(trim($v))) {
            $this->params[$k] = $v;
         }
      }
      
      foreach($attributes as $k => $v) {
         if(strlen(trim($v))) {
            $this->attributes[$k] = $v;
         }
      }
      
   }
   
   function getFlashVarsForGet() {
      $flashvars = "";
      foreach($this->flashvars as $k => $v) {
         $flashvars .= "$k=" . $v . "&";
      }
      return rtrim($flashvars, "&");
   }


   function getJavascript() {
      $flashvars = $this->_getVarsJS('flashvars');
      $params = $this->_getVarsJS('params');
      $attributes = $this->_getVarsJS('attributes');
      $str = <<< JS
      <script type="text/javascript">
         $flashvars
         $params
         $attributes
         if(swfobject.hasFlashPlayerVersion('$this->flashVersion')) {
            swfobject.embedSWF(
               '{$this->params['movie']}', 
               '{$this->id}', 
               '{$this->params['width']}', '{$this->params['height']}', '$this->flashVersion', 
               '/flash/expressInstall.swf', 
               flashvars, params, attributes
            );
         } else {
            Element.replace('{$this->id}', 
               '<p>' +
               '<a href="http://www.adobe.com/go/getflashplayer">' +
               '<img src="/images/graphics/get_flash_player.gif" alt="Get Adobe Flash player" />' + 
               '</a></p>'
            );
         }
      </script>
JS;
      return $str;
   }
   
   
   
   function getHtml() {
      $str = <<< HTML
      <div id="{$this->id}">
         <p>
         <a href="http://www.adobe.com/go/getflashplayer">
            <img src="/images/graphics/get_flash_player.gif" alt="Get Adobe Flash player" />
         </a>
      </p>
      </div>
HTML;
      return $str;      
   }
   
   function setPlaylist($courseid) {
      $this->flashvars['playlist'] = 'http://www.htinstitute.co.il/courses/playlist/course/'.$courseid;
   }
   
   function getPlaylist() {
      
   }
   
}


?>